/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package extracao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Rodrigo L. Benites
 */
public class InsereBD {
    
    private final String db;
    private final String user;
    private final String passwd;
    
    public InsereBD() {
        //this.db = "jdbc:derby://localhost:1527/DadosPreReq";
        //this.user = "nbuser";
        //this.passwd = "eruseden";
        
        this.db = "jdbc:mysql://143.106.150.216:3306/SatodaDB?zeroDateTimeBehavior=convertToNull";
        this.user = "satoda";
        this.passwd = "adotas2014";

    }
    public void inicia () {
        System.out.println("Iniciando driver");
        
        // TODO code application logic here
        try{
            //Class.forName("org.apache.derby.jdbc.ClientDriver");
            Class.forName("com.mysql.jdbc.Driver");
         } catch(ClassNotFoundException e){
            System.out.println(e);
        }
        
    }
    
    public void insere (String discip, String preReq, int familia) {
        
        //String query = "INSERT INTO NBUSER.PREREQ VALUES ('" + discip + "', '" + 
        //        preReq + "', " + familia + ")";
        
        String query = "INSERT INTO SatodaDB.PREREQ VALUES ('" + discip + "', '" + 
                preReq + "', " + familia + ")";
        
        
        try{
            Connection con = DriverManager.getConnection(db, user, passwd);
            Statement stmt = con.createStatement();
            
            int rs = stmt.executeUpdate(query);
        
        } catch(SQLException e){
            System.err.println(e);
        }
    }
    
    
}
